﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Visuals;

namespace Silvermoon.Controls
{
    /// <summary>
    /// Control used with <see cref="T:DropDownButton"/>.
    /// </summary>
    public class DropDownMenu : ContextMenu
    {
        protected override void OnLayout()
        {
            base.OnLayout();

            // Menu hides the scrollbar so add it here, but change the location due to other margins set in Menu:

            if (this.ShowScrollbar && scrollBarAlpha > 0)
            {
                SubControls.Add(VScrollBar);
                int r = Width - ItemsMargin.RightZero - VScrollBar.Width - 1;
                VScrollBar.Location = new System.Drawing.Point(r, 0);
            }
        }

        /// <summary>
        /// Menu never sets IsScrollbarVisible to true, but determines the up/down button visibility, which DropDownMenu does not have or need,
        /// so set the scrollbar to visible again here:
        /// </summary>
        protected override void OnTopOffsetChanged(int oldOffset, int newOffset)
        {
            ShowScrollbar = true;
        }

        /// <summary>
        /// Menu sets the selected item to the first, when drop down appears, which is not needed here:
        /// </summary>
        protected override void SetSelectedItem()
        {
            if (SelectedItem == null && Items.Count > 0) SelectedItem = GetItem(0);
        }
    }
}
